home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-02.iso / Pakiet bezpieczenstwa / mini Pentoo LiveCD 2006.1 / mpentoo-2006.1.iso / livecd.squashfs / usr / lib / mozilla-firefox / include / content / nsINodeInfo.h < prev    next >
C/C++ Source or Header  |  2006-05-08  |  10KB  |  312 lines

  1. /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* ***** BEGIN LICENSE BLOCK *****
  3.  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  4.  *
  5.  * The contents of this file are subject to the Mozilla Public License Version
  6.  * 1.1 (the "License"); you may not use this file except in compliance with
  7.  * the License. You may obtain a copy of the License at
  8.  * http://www.mozilla.org/MPL/
  9.  *
  10.  * Software distributed under the License is distributed on an "AS IS" basis,
  11.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  12.  * for the specific language governing rights and limitations under the
  13.  * License.
  14.  *
  15.  * The Original Code is Mozilla Communicator client code.
  16.  *
  17.  * The Initial Developer of the Original Code is
  18.  * Netscape Communications Corporation.
  19.  * Portions created by the Initial Developer are Copyright (C) 1998
  20.  * the Initial Developer. All Rights Reserved.
  21.  *
  22.  * Contributor(s):
  23.  *
  24.  * Alternatively, the contents of this file may be used under the terms of
  25.  * either of the GNU General Public License Version 2 or later (the "GPL"),
  26.  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  27.  * in which case the provisions of the GPL or the LGPL are applicable instead
  28.  * of those above. If you wish to allow use of your version of this file only
  29.  * under the terms of either the GPL or the LGPL, and not to allow others to
  30.  * use your version of this file under the terms of the MPL, indicate your
  31.  * decision by deleting the provisions above and replace them with the notice
  32.  * and other provisions required by the GPL or the LGPL. If you do not delete
  33.  * the provisions above, a recipient may use your version of this file under
  34.  * the terms of any one of the MPL, the GPL or the LGPL.
  35.  *
  36.  * ***** END LICENSE BLOCK ***** */
  37.  
  38. /*
  39.  * nsINodeInfo is an interface to node info, such as name, prefix, namespace
  40.  * ID and possibly other data that is shared between nodes (elements
  41.  * and attributes) that have the same name, prefix and namespace ID within
  42.  * the same document.
  43.  *
  44.  * nsNodeInfoManager's are internal objects that manage a list of
  45.  * nsINodeInfo's, every document object should hold a strong reference to
  46.  * a nsNodeInfoManager and every nsINodeInfo also holds a strong reference
  47.  * to their owning manager. When a nsINodeInfo is no longer used it will
  48.  * automatically remove itself from its owner manager, and when all
  49.  * nsINodeInfo's have been removed from a nsNodeInfoManager and all external
  50.  * references are released the nsNodeInfoManager deletes itself.
  51.  *
  52.  * -- jst@netscape.com
  53.  */
  54.  
  55. #ifndef nsINodeInfo_h___
  56. #define nsINodeInfo_h___
  57.  
  58. #include "nsISupports.h"
  59. #include "nsIAtom.h"
  60. #include "nsAString.h"
  61. #include "nsDOMString.h"
  62. #include "nsINameSpaceManager.h"
  63. #include "nsCOMPtr.h"
  64.  
  65. // Forward declarations
  66. class nsIDocument;
  67. class nsIURI;
  68. class nsIPrincipal;
  69. class nsNodeInfoManager;
  70.  
  71. // IID for the nsINodeInfo interface
  72. #define NS_INODEINFO_IID      \
  73. { 0x290ecd20, 0xb3cb, 0x11d8, \
  74.   { 0xb2, 0x67, 0x00, 0x0a, 0x95, 0xdc, 0x23, 0x4c } }
  75.  
  76. class nsINodeInfo : public nsISupports
  77. {
  78. public:
  79.   NS_DEFINE_STATIC_IID_ACCESSOR(NS_INODEINFO_IID)
  80.  
  81.   nsINodeInfo()
  82.     : mInner(nsnull, nsnull, kNameSpaceID_None),
  83.       mOwnerManager(nsnull)
  84.   {
  85.   }
  86.  
  87.   /*
  88.    * Get the name from this node as a string, this does not include the prefix.
  89.    *
  90.    * For the HTML element "<body>" this will return "body" and for the XML
  91.    * element "<html:body>" this will return "body".
  92.    */
  93.   void GetName(nsAString& aName) const
  94.   {
  95.     mInner.mName->ToString(aName);
  96.   }
  97.  
  98.   /*
  99.    * Get the name from this node as an atom, this does not include the prefix.
  100.    * This function never returns a null atom.
  101.    *
  102.    * For the HTML element "<body>" this will return the "body" atom and for
  103.    * the XML element "<html:body>" this will return the "body" atom.
  104.    */
  105.   nsIAtom* NameAtom() const
  106.   {
  107.     return mInner.mName;
  108.   }
  109.  
  110.   /*
  111.    * Get the qualified name from this node as a string, the qualified name
  112.    * includes the prefix, if one exists.
  113.    *
  114.    * For the HTML element "<body>" this will return "body" and for the XML
  115.    * element "<html:body>" this will return "html:body".
  116.    */
  117.   virtual void GetQualifiedName(nsAString& aQualifiedName) const = 0;
  118.  
  119.   /*
  120.    * Get the local name from this node as a string, GetLocalName() gets the
  121.    * same string as GetName() but only if the node has a prefix and/or a
  122.    * namespace URI. If the node has neither a prefix nor a namespace URI the
  123.    * local name is a null string.
  124.    *
  125.    * For the HTML element "<body>" in a HTML document this will return a null
  126.    * string and for the XML element "<html:body>" this will return "body".
  127.    */
  128.   virtual void GetLocalName(nsAString& aLocalName) const = 0;
  129.  
  130.   /*
  131.    * Get the prefix from this node as a string.
  132.    *
  133.    * For the HTML element "<body>" this will return a null string and for
  134.    * the XML element "<html:body>" this will return the string "html".
  135.    */
  136.   void GetPrefix(nsAString& aPrefix) const
  137.   {
  138.     if (mInner.mPrefix) {
  139.       mInner.mPrefix->ToString(aPrefix);
  140.     } else {
  141.       SetDOMStringToNull(aPrefix);
  142.     }
  143.   }
  144.  
  145.   /*
  146.    * Get the prefix from this node as an atom.
  147.    *
  148.    * For the HTML element "<body>" this will return a null atom and for
  149.    * the XML element "<html:body>" this will return the "html" atom.
  150.    */
  151.   nsIAtom* GetPrefixAtom() const
  152.   {
  153.     return mInner.mPrefix;
  154.   }
  155.  
  156.   /*
  157.    * Get the namespace URI for a node, if the node has a namespace URI.
  158.    *
  159.    * For the HTML element "<body>" in a HTML document this will return a null
  160.    * string and for the XML element "<html:body>" (assuming that this element,
  161.    * or one of it's ancestors has an
  162.    * xmlns:html='http://www.w3.org/1999/xhtml' attribute) this will return
  163.    * the string "http://www.w3.org/1999/xhtml".
  164.    */
  165.   virtual nsresult GetNamespaceURI(nsAString& aNameSpaceURI) const = 0;
  166.  
  167.   /*
  168.    * Get the namespace ID for a node if the node has a namespace, if not this
  169.    * returns kNameSpaceID_None.
  170.    *
  171.    * For the HTML element "<body>" in a HTML document this will return
  172.    * kNameSpaceID_None and for the XML element "<html:body>" (assuming that
  173.    * this element, or one of it's ancestors has an
  174.    * xmlns:html='http://www.w3.org/1999/xhtml' attribute) this will return
  175.    * the namespace ID for "http://www.w3.org/1999/xhtml".
  176.    */
  177.   PRInt32 NamespaceID() const
  178.   {
  179.     return mInner.mNamespaceID;
  180.   }
  181.  
  182.   /*
  183.    * Get and set the ID attribute atom for this node.
  184.    * See http://www.w3.org/TR/1998/REC-xml-19980210#sec-attribute-types
  185.    * for the definition of an ID attribute.
  186.    *
  187.    */
  188.   nsIAtom* GetIDAttributeAtom() const
  189.   {
  190.     return mIDAttributeAtom;
  191.   }
  192.  
  193.   void SetIDAttributeAtom(nsIAtom* aID)
  194.   {
  195.     mIDAttributeAtom = aID;
  196.   }
  197.  
  198.   /**
  199.    * Get the owning node info manager. Only to be used inside Gecko, you can't
  200.    * really do anything with the pointer outside Gecko anyway.
  201.    */
  202.   nsNodeInfoManager *NodeInfoManager() const
  203.   {
  204.     return mOwnerManager;
  205.   }
  206.  
  207.   /*
  208.    * Utility functions that can be used to check if a nodeinfo holds a specific
  209.    * name, name and prefix, name and prefix and namespace ID, or just
  210.    * namespace ID.
  211.    */
  212.   PRBool Equals(nsINodeInfo *aNodeInfo) const
  213.   {
  214.     return aNodeInfo == this || aNodeInfo->Equals(mInner.mName, mInner.mPrefix,
  215.                                                   mInner.mNamespaceID);
  216.   }
  217.  
  218.   PRBool NameAndNamespaceEquals(nsINodeInfo *aNodeInfo) const
  219.   {
  220.     return aNodeInfo == this || aNodeInfo->Equals(mInner.mName,
  221.                                                   mInner.mNamespaceID);
  222.   }
  223.  
  224.   PRBool Equals(nsIAtom *aNameAtom) const
  225.   {
  226.     return mInner.mName == aNameAtom;
  227.   }
  228.  
  229.   PRBool Equals(nsIAtom *aNameAtom, nsIAtom *aPrefixAtom) const
  230.   {
  231.     return (mInner.mName == aNameAtom) && (mInner.mPrefix == aPrefixAtom);
  232.   }
  233.  
  234.   PRBool Equals(nsIAtom *aNameAtom, PRInt32 aNamespaceID) const
  235.   {
  236.     return ((mInner.mName == aNameAtom) &&
  237.             (mInner.mNamespaceID == aNamespaceID));
  238.   }
  239.  
  240.   PRBool Equals(nsIAtom *aNameAtom, nsIAtom *aPrefixAtom,
  241.                 PRInt32 aNamespaceID) const
  242.   {
  243.     return ((mInner.mName == aNameAtom) &&
  244.             (mInner.mPrefix == aPrefixAtom) &&
  245.             (mInner.mNamespaceID == aNamespaceID));
  246.   }
  247.  
  248.   PRBool NamespaceEquals(PRInt32 aNamespaceID) const
  249.   {
  250.     return mInner.mNamespaceID == aNamespaceID;
  251.   }
  252.  
  253.   virtual PRBool Equals(const nsAString& aName) const = 0;
  254.   virtual PRBool Equals(const nsAString& aName,
  255.                         const nsAString& aPrefix) const = 0;
  256.   virtual PRBool Equals(const nsAString& aName,
  257.                         PRInt32 aNamespaceID) const = 0;
  258.   virtual PRBool Equals(const nsAString& aName, const nsAString& aPrefix,
  259.                         PRInt32 aNamespaceID) const = 0;
  260.   virtual PRBool NamespaceEquals(const nsAString& aNamespaceURI) const = 0;
  261.   // switch to UTF8 - this allows faster access for consumers
  262.   virtual PRBool QualifiedNameEquals(const nsACString& aQualifiedName) const = 0;
  263.  
  264.   /*
  265.    * Retrieve a pointer to the document that owns this node info.
  266.    */
  267.   virtual nsIDocument* GetDocument() const = 0;
  268.  
  269.   /*
  270.    * Retrieve a pointer to the principal for the document of this node info.
  271.    */
  272.   virtual nsIPrincipal *GetDocumentPrincipal() const = 0;
  273.  
  274. protected:
  275.   /*
  276.    * nsNodeInfoInner is used for two things:
  277.    *
  278.    *   1. as a member in nsNodeInfo for holding the name, prefix and
  279.    *      namespace ID
  280.    *   2. as the hash key in the hash table in nsNodeInfoManager
  281.    *
  282.    * nsNodeInfoInner does not do any kind of reference counting,
  283.    * that's up to the user of this class. Since nsNodeInfoInner is
  284.    * typically used as a member of nsNodeInfo, the hash table doesn't
  285.    * need to delete the keys. When the value (nsNodeInfo) is deleted
  286.    * the key is automatically deleted.
  287.    */
  288.  
  289.   class nsNodeInfoInner
  290.   {
  291.   public:
  292.     nsNodeInfoInner(nsIAtom *aName, nsIAtom *aPrefix, PRInt32 aNamespaceID)
  293.       : mName(aName), mPrefix(aPrefix), mNamespaceID(aNamespaceID)
  294.     {
  295.     }
  296.  
  297.     nsIAtom*            mName;
  298.     nsIAtom*            mPrefix;
  299.     PRInt32             mNamespaceID;
  300.   };
  301.  
  302.   // nsNodeInfoManager needs to pass mInner to the hash table.
  303.   friend class nsNodeInfoManager;
  304.  
  305.   nsNodeInfoInner mInner;
  306.  
  307.   nsCOMPtr<nsIAtom> mIDAttributeAtom;
  308.   nsNodeInfoManager* mOwnerManager; // Strong reference!
  309. };
  310.  
  311. #endif /* nsINodeInfo_h___ */
  312.